﻿//战魂铭人的扫线SHADER
Shader "Dan/2D/LineORG"
{
    Properties
    {
        [HDR]_Color("Emission Color",Color)=(0.5,0.5,0.5,1)
        _MainTex ("maintex", 2D) = "white" {}
        _LineTex("linetex", 2D) = "white" {}
        _Distance("_Distance",float) = 1
        // _PointCount("_PointCount",float) = 1
        // _PointCount2("_PointCount2",float) = 1
        _Speed("_Speed",float) = 2
        _Opacity("_Opacity",Range(0,1)) = 1
        _Power("_Power",Int) = 32
        _Strength("_Strength",float) = 0.5
    }
    SubShader
    {
         Tags { "CanUseSpriteAtlas" = "true" "IGNOREPROJECTOR" = "true" "PreviewType" = "Plane" "QUEUE" = "Transparent" "RenderType" = "Transparent" }
         Blend SrcAlpha OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            sampler2D _LineTex;
            float4 _MainTex_ST;
            float4 _Color;
            float _Distance;
            float _PointCount;
            float _PointCount2;
            float _Speed;
            float _Opacity;
            float _Power;
            float _Strength;
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                    float4 col;
                    float4 flow;
                    
                    
                    float timespeed = frac( _Time.y * _Speed) * 0.9 + 0.1;

                    float4 lineTex = tex2D(_LineTex, i.uv);
                    float lineDotColor = dot(lineTex, float4(1, 0.004, 1.55e-05, 6.33e-08));
                    
                    float delta = lineDotColor *_Distance;
                    
                    float p1 = delta -timespeed;
                    
                    float p3 = timespeed < delta;
                    
                    delta =saturate(1- abs(p1));
                    delta = pow(delta,_Power) ;
                    delta *=delta;
                    delta *=delta;
                    delta *=delta;

                    p1 = log2(delta);         
                    p1 = exp2(p1 *100);
                    
                    timespeed = (p3) ? p1 : delta;
                    
                    float4 mask = tex2D(_MainTex, i.uv);
                   
                    flow = mask * (timespeed + _Opacity) + timespeed *_Strength;
                    
                    col.xyz = saturate(flow.www * flow.xyz);
                    col.w = saturate(flow.w);
                return col*_Color;      
                    
                    
                    
                    
            }
            ENDCG
        }
    }
}
